//
//  EntryTest.m
//  CEDict
//
//  Created by Eric Nadeau on 07-06-02.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "EntryTest.h"


@implementation EntryTest

// Tests the static contains:query method with 'caterpillar' and 'cat'
-(void) testStaticContainsTrue
{
	NSString* s1 = @"caterpillar";
	NSString* s2 = @"cat";
	
	bool expected = true;
	bool actual = [Entry contains: s1 query: s2];
	
	STAssertEquals( expected, actual, @"Checks if 'caterpillar' contains 'cat'." );
}

// Tests the static contains:query method with 'caterpillar' and 'cap'
-(void) testStaticContainsFalse
{
	NSString* s1 = @"caterpillar";
	NSString* s2 = @"cap";
	
	bool expected = false;
	bool actual = [Entry contains: s1 query: s2];
	
	STAssertEquals( expected, actual, @"Checks if 'caterpillar' doesn't contain 'cap'." );
}

// Tests the static oneOfContains:query method with 
// (Barbouille, Ti-Gris, McDog, caterpillar) and 'cat'
-(void) testStaticArrayContainsTrue
{
	NSArray* a = 
		[NSArray arrayWithObjects:
			@"Barbouille", @"Ti-Gris", @"McDog", @"caterpillar", nil
		];
	NSString* s2 = @"cat";
	
	bool expected = true;
	bool actual = [Entry oneOfContains:a query: s2];
	
	STAssertEquals( expected, actual, @"Checks if an array contains 'cat'." );
}

// Tests the static oneOfContains:query method with 
// (Barbouille, Ti-Gris, McDog, caterpillar) and 'cap'
-(void) testStaticArrayContainsFalse
{
	NSArray* a = [NSArray arrayWithObjects:
			@"Barbouille", @"Ti-Gris", @"McDog", @"caterpillar", nil
	];
	NSString* s2 = @"cap";
	
	bool expected = false;
	bool actual = [Entry oneOfContains:a query: s2];
	
	STAssertEquals( expected, actual, @"Checks if an array doesn't contain 'cap'." );
}


-(void) testMatches:(Entry*)word query:(NSString*)query
{
	STAssertTrue( 
		[word matches: query], 
		@"Checks if the entry matches '%s'", 
		query 
	);
}

-(void) testDoesntMatch:(Entry*)word query:(NSString*)query
{
	STAssertFalse( 
		[word matches: query], 
		@"Checks if the entry doesn't match '%s'",
		query 
	);	
}

// Tests the matches method on an Entry instance
-(void) testMatches
{
	NSString* simplified = [NSString stringWithCString: "你好"];
	NSString* traditional = [NSString stringWithCString: "你好"];
	NSString* pinyin = @"ni3 hao3";
	NSArray* english = 
		[NSArray arrayWithObjects: @"hello", @"how are you", nil];
	
	Entry* e = 
		[
			[Entry alloc] 
				initWithSimplifed:simplified 
				andTraditional:traditional 
				andPinyin:pinyin 
				andEnglish:english
		];
	
	[self testMatches:e query: simplified];
	[self testMatches:e query: traditional];
	[self testMatches:e query: pinyin];
	[self testMatches:e query:@"hao"];
	[self testMatches:e query:@"hello"];
	[self testDoesntMatch:e query:@"wo"];
}

@end
